//
//  MemberListViewController.m
//  HJB
//
//  Created by jiezsoft.com on 14-10-10.
//  Copyright (c) 2014年 jiezsoft.com. All rights reserved.
//

#import "MemberListViewController.h"
#import "GenerateQRCodeViewController.h"
#import "AddMemberViewController.h"
#import "MJRefresh.h"
#import "TagsCell.h"
#import "MemberListCell.h"
#import "MembershipDetailsViewController.h"
#import "TheLoginViewController.h"
#import "MemberListModel.h"
#import "FilterView.h"
@interface MemberListViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate,FilterViewDelegate>
@property (strong, nonatomic) NSString*orderField;
@end
@implementation MemberListViewController
{
    UISearchBar *search;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    NSMutableArray*modelArray;
    NSMutableArray*ScreeningModelArray;
    NSMutableArray*searchBeans;
    UITableView *table;
    UIButton*screeningBtn;
    int pageNumber;
    MBProgressHUD *progressHud;
    UITextField*searchTextField;
    UIView*tableHeaderView;
    UIView*myToolBar;
    UIButton* screeningBtnImage;
    UIButton* addBtn;
    UIButton*sat;
    UIButton*sat1;
    UIButton*sat2;
    UIView*addView;
    UIView*optionsView;
    BOOL saveAccount;
    NSString* TotalCount;
}
@synthesize alt = alt;

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    // 禁用 iOS7 返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.orderField=@"date";
    [self requestData];
    saveAccount=YES;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self addFooter];
    [self addheader];
    [self setNavigation];
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [table registerClass:[MemberListCell class] forCellReuseIdentifier:@"MemberListViewController"];
    [self.view addSubview:table];
    
    if ([self.chooseState isEqualToString:@"选择"]) {
        tableHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
        tableHeaderView.backgroundColor=zuiqianhuiColor;
        table.tableHeaderView=tableHeaderView;
    }else{
        
        [self tableHeaderView];
        
    }

    modelArray=[[NSMutableArray alloc]init];
    ScreeningModelArray=[[NSMutableArray alloc]init];
    searchBeans=[[NSMutableArray alloc]init];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"member" forKey:@"filterType"];
    [HttpRequest requestData:@"Common/AdvancedFilterList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray * mItemsArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                for (NSDictionary *dic in mItemsArray) {
                    MemberListModel *dataModel=[MemberListModel ScreeningDataModelWithDict:dic];
                    [ScreeningModelArray addObject:dataModel];
                }
        }else{
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
}
-(void)closeKeyBoad1{
    
    [optionsView removeFromSuperview];
  
}
-(void)addoptions:(UIButton *)sender{
    

    [optionsView removeFromSuperview];
    saveAccount=! saveAccount;
    
    if (!saveAccount) {
        optionsView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        [self.view addSubview:optionsView];
        
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad1)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [optionsView addGestureRecognizer:singleFingerOne];
        addView=[[UIView alloc]initWithFrame:CGRectMake(ScreenWidth-185, 64+3.5, 170, 336/2/3*2)];
        addView.backgroundColor=[UIColor colorWithRed:40/255.0 green:65/255.0 blue:1/255.0 alpha:1.0];
        addView.alpha=0.94;
        [addView.layer setCornerRadius:3.0]; //设置矩圆角半径
        [addView.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){40/255.0,65/255.0, 1/255.0, 1.0});
        [addView.layer setBorderColor:tureBTncolorref];//边框颜色
        
        [optionsView addSubview:addView];
        UIImage *img=[UIImage imageNamed:@"xialajiantou"];
        UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-38, 64, 10, 3.5)];
        imageview.image=img;
        imageview.alpha=1;
        [optionsView addSubview:imageview];
        
        NSArray *buttonContent = @[@"         录入会员",@"           扫公众号"];
        NSArray *buttonContentimage = @[@"tinajiahuiyuan",@"erweimahuiyuan"];
        for (int i = 0;  i<2; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(0, 2.5+336/2/3*i, 170, 50);
            [button setTitle:[buttonContent objectAtIndex:i] forState:UIControlStateNormal];
            button.titleLabel.font=[UIFont systemFontOfSize:15];
            button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
            [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = i+1;
            button.alpha=0.88;
            [addView addSubview:button];
            UIButton *shanghubutton = [UIButton buttonWithType:UIButtonTypeCustom];
            shanghubutton.frame = CGRectMake(35, 12.5+336/2/3*i, 30, 30);
            [shanghubutton setImage:[UIImage imageNamed:[buttonContentimage objectAtIndex:i]] forState:UIControlStateNormal];
            //          [shanghubutton setImage: forState:UIControlStateNormal];
            [addView addSubview:shanghubutton];
            if (i==0) {
                
            }else{
                UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(10, 336/2/3*i, 170-20, 0.35)];
                line.backgroundColor=luseColor;
                [addView addSubview:line];
            }
        }
        
    }else{
        [addView removeFromSuperview];
        
    }
    
}
- (void)buttonAction:(UIButton *)button{
    
    [optionsView removeFromSuperview];
    switch (button.tag)
    {
        case 1:
            
            if (button.tag==1) {
                
                [addView removeFromSuperview];
                AddMemberViewController *detailViewController = [[AddMemberViewController alloc] init];
                [self.navigationController pushViewController:detailViewController animated:YES];
                
            }
            break;
            
        case 2:
            
            if (button.tag==2) {
                
                [addView removeFromSuperview];
                
                GenerateQRCodeViewController*detailViewController = [[GenerateQRCodeViewController alloc] init];
                detailViewController.QrCode=@"GetCompanyQrCode";
                [self.navigationController pushViewController:detailViewController animated:YES];
          
            }
            
            break;
            
            
            
        default:
            break;
    }
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [searchTextField resignFirstResponder];
    [self requestData];
    
    return YES;
    
}
-(void)requestData{
    
    modelArray=[[NSMutableArray alloc]init];
    pageNumber = 1;
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"1" forKey:@"pageIndex"];
    [param setValue:@"20" forKey:@"pageSize"];
    [param setValue:self.orderField forKey:@"orderField"];
    [param setValue:self.orderSort forKey:@"orderSort"];
    [param setValue:searchTextField.text forKey:@"searchWord"];
    [param setValue:searchBeans forKey:@"searchBeans"];
    if (searchBeans .count>0) {
        [screeningBtnImage setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    }
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Business/Member/List" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
                      NSLog(@"====%@",severDataDict.dataDict);
            if (searchBeans.count>0) {
                
                UIImage *img=[UIImage imageNamed:@"shaixuan_hight"];
                UIImage *tinted = [img rt_tintedImageWithColor:luseColor];
                [screeningBtn setTitleColor:luseColor forState:UIControlStateNormal];
                [screeningBtnImage setImage:tinted forState:UIControlStateNormal];                
          
            }else{
                [screeningBtn setTitleColor:shenhuiColor forState:UIControlStateNormal];
                [screeningBtnImage setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
            }
           
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                TotalCount=[severDataDict.dataDict objectForKey:@"TotalCount"];
                if ([self.chooseState isEqualToString:@"选择"]) {
                    UILabel*totalcount=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 200, 40)];
                    totalcount.text=[NSString stringWithFormat:@"共有 %@ 个结果",TotalCount];
                    totalcount.font=[UIFont systemFontOfSize:14];
                    [tableHeaderView addSubview:totalcount];
                }
                NSMutableArray * mItemsArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (NSDictionary *dic in mItemsArray) {
                        MemberListModel *dataModel=[MemberListModel dataModelWithDict:dic];
                        [modelArray addObject:dataModel];
                        }
                [table reloadData];
                }else{
                [Global hideProgressHUDInternal:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    
                    TheLoginViewController*vc1=[[TheLoginViewController alloc] init];
                    
                    [self.navigationController pushViewController:vc1 animated:YES];
                }
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    

    
}
//下拉刷新最新数据
- (void)addheader
{

    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
    footer.scrollView = table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        searchBeans=nil;
        [self requestData];
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
}

//上拉刷新数据
- (void)addFooter
{
    
    
    MJRefreshFooterView* footer = [MJRefreshFooterView footer];
    footer.scrollView = table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        if (TotalCount.intValue/20>=pageNumber) {
            pageNumber++;
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            if (Token ==nil) {
                Token=@"dd";
            }
            NSMutableDictionary *param = [NSMutableDictionary new];
            [param setValue:Token forKey:@"tokenId"];
            [param setValue:[NSString stringWithFormat:@"%d" ,pageNumber] forKey:@"pageIndex"];
            [param setValue:@"20" forKey:@"pageSize"];
            [param setValue:self.orderField forKey:@"orderField"];
            [param setValue:self.orderSort forKey:@"orderSort"];
            [param setValue:searchTextField.text forKey:@"searchWord"];
            [param setValue:searchBeans forKey:@"searchBeans"];
            NSLog(@"====%@",param);
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            [HttpRequest requestData:@"Business/Member/List" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
//
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSMutableArray * mItemsArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                        for (NSDictionary *dic in mItemsArray) {
                            MemberListModel *dataModel=[MemberListModel dataModelWithDict:dic];
                            [modelArray addObject:dataModel];
                        }
                        [table reloadData];
              }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            }else{
            
            NSString *requestResultStr=@"没有更多数据了！";
            [Global showTextHudSub:requestResultStr view:self.view];
            }
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [table reloadData];
    [refreshView endRefreshing];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [modelArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MemberListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MemberListViewController"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model=modelArray[indexPath.row];
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  90;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView == table) {
    MemberListModel *ScreeningModel=modelArray[indexPath.row];
        if ([self.chooseState isEqualToString:@"选择"]) {
        [self.delegate secondViewController:self memberIdStr:ScreeningModel.memberId userName:ScreeningModel.userName phone:ScreeningModel.phone sex:ScreeningModel.sex consigneeName:ScreeningModel.consigneeName consigneeAddr:ScreeningModel.address consigneePhone:ScreeningModel.consigneePhone];
           [self.navigationController popViewControllerAnimated:YES];
        }else{
            MembershipDetailsViewController *detailViewController = [[MembershipDetailsViewController alloc] init];
            detailViewController.memberId=ScreeningModel.memberId;
            [self.navigationController pushViewController:detailViewController animated:YES];
        }
        
        
        
        
    }
}
-(void)sat:(UIButton*)sender{
    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [sat2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    searchBeans=nil;
    self.orderField=@"date";
    [self requestData];
}
-(void)sat1:(UIButton*)sender{
    self.orderField=@"amount";
    [self requestData];
    [sat setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [sat2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    saveAccount=!saveAccount;
    if (saveAccount) {
        self.orderSort=@"desc";
        }else{
        
        self.orderSort=@"asc";
}
}
-(void)sat2:(UIButton*)sender{
    self.orderField=@"active";
    [self requestData];
    [sat setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    saveAccount=!saveAccount;
    if (saveAccount) {
        self.orderSort=@"desc";
    }else{
        self.orderSort=@"asc";
    }
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}
- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
-(void)setNavigation{
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    self.navigationController.navigationBarHidden=NO;
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    UIView* sousuoView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth*570/750, 65/2)];
    sousuoView.backgroundColor=zuiqianhuiColor;
    UIButton *screeningBtnImage1 = [[UIButton alloc] initWithFrame:CGRectMake(2, 4, 50/2, 50/2)];
    [screeningBtnImage1 setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
    [sousuoView addSubview:screeningBtnImage1];
    searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(screeningBtnImage1.right,1, ScreenWidth*500/750,65/2)];
    [searchTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
    searchTextField.placeholder = @"会员/手机号/姓名"; //默认显示的字
    searchTextField.font = [UIFont systemFontOfSize: 14];
    searchTextField.tag=22;
    searchTextField.returnKeyType = UIReturnKeyDone;
    searchTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    searchTextField.delegate = self;
    searchTextField.tintColor =tintColors;
    [sousuoView addSubview:searchTextField];
    
    self.navigationItem.titleView = sousuoView;
    
    addBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0, 60/2, 60/2)];
    [addBtn setImage:[UIImage imageNamed:@"tianjia"] forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addoptions:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:addBtn];
    self.navigationItem.rightBarButtonItem = myBtnBtn;

    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:17];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    searchTextField.inputAccessoryView = myToolBar;

}
-(void)BackAction:(UIButton *)sender{
    [searchTextField resignFirstResponder];
    [self.navigationController popViewControllerAnimated:YES];
    }
-(void)OnTapDone{
    
    [searchTextField resignFirstResponder];
    
}
-(void)tableHeaderView{
    
    tableHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
    tableHeaderView.backgroundColor=zuiqianhuiColor;
    table.tableHeaderView=tableHeaderView;
    
    sat=[[UIButton alloc]initWithFrame:CGRectMake(18, 0, ScreenWidth/4, 40)];
    [sat setTitle:@"最新" forState:UIControlStateNormal];
    [sat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    sat.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    sat.titleLabel.font=[UIFont systemFontOfSize:ScreeningFont];
    [sat addTarget:self action:@selector(sat:) forControlEvents:UIControlEventTouchUpInside];
    [tableHeaderView addSubview:sat];
    
    
    sat1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3-20, 0, ScreenWidth/4, 40)];
    [sat1 setTitle:@"成交额" forState:UIControlStateNormal];
    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    sat1.titleLabel.font=[UIFont systemFontOfSize:ScreeningFont];
    sat1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [sat1 addTarget:self action:@selector(sat1:) forControlEvents:UIControlEventTouchUpInside];
    sat1.titleLabel.textAlignment=NSTextAlignmentCenter;
    [tableHeaderView addSubview:sat1];
    
    
    sat2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3*2-30, 0, ScreenWidth/4, 40)];
    [sat2 setTitle:@"活跃度" forState:UIControlStateNormal];
    sat2.titleLabel.font=[UIFont systemFontOfSize:ScreeningFont];
    [sat2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    sat2.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [sat2 addTarget:self action:@selector(sat2:) forControlEvents:UIControlEventTouchUpInside];
    sat2.titleLabel.textAlignment=NSTextAlignmentCenter;
    [tableHeaderView addSubview:sat2];
    
    screeningBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-78,  0, 60,40)];
    [screeningBtn.layer setCornerRadius:2.0];
    [screeningBtn.layer setBorderWidth:0];
    [screeningBtn.layer setMasksToBounds:YES];
   [screeningBtn addTarget:self action:@selector(sxuan:) forControlEvents:UIControlEventTouchUpInside];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){153/255.0,153/255.0, 153/255.0, 1.0   });
    [screeningBtn.layer setBorderColor:colorref2];//边框颜色
    [screeningBtn setTitle:@"筛选" forState:UIControlStateNormal];
    screeningBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [screeningBtn setTitleColor:shenhuiColor forState:UIControlStateNormal];
    screeningBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [tableHeaderView addSubview:screeningBtn];
    
    screeningBtnImage = [[UIButton alloc] initWithFrame:CGRectMake(3.5,5, 30, 30)];
    [screeningBtnImage setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
   [screeningBtnImage addTarget:self action:@selector(sxuan:) forControlEvents:UIControlEventTouchUpInside];
    [screeningBtn addSubview:screeningBtnImage];
    


}
-(void)sxuan:(UIButton*)sender{
    FilterView *filterView=[FilterView FilterViewWithSize:CGSizeMake(ScreenWidth, ScreenHeight)];
    filterView.typeStr=@"member";
    filterView.delegate=self;
    filterView.selectedSearchBeansArray=searchBeans;
    [filterView show];
    
}
#pragma mark FilterViewDelegate
-(void)confirmFilter:(NSMutableArray *)searchBeansArray
{
    searchBeans=searchBeansArray;
    [self requestData];
}


@end
